package com.jiegui.payinterface.utils;



import com.jiegui.common.utils.AmountUtils;
import com.jiegui.payinterface.bean.InterfacePaymentBean;
import com.jiegui.payinterface.bean.PaymentNotifyBean;

import java.util.Map;

/**
 * @author wuqicheng
 * @date 2021/3/11
 */
public class PaymentHelper {

    /**
     * 支付实体适配器
     * 将旧的支付信息转换为新的
     */
    public static InterfacePaymentBean conver(Map<String, String> map) {
        InterfacePaymentBean interfacePaymentBean = new InterfacePaymentBean();
        interfacePaymentBean.setBillCode(map.get("out_trade_no"));
        interfacePaymentBean.setAmount(Double.parseDouble(map.get("total_fee")));
        interfacePaymentBean.setRemark(map.get("body"));
        interfacePaymentBean.setAttach(map.get("attach"));
        interfacePaymentBean.setNotifyUrl(map.get("notify_url"));
        interfacePaymentBean.setUserId(map.get("openid"));
        interfacePaymentBean.setPayType(map.get("trade_type"));
        interfacePaymentBean.setInterfaceCode(map.get("interfaceCode"));
        return interfacePaymentBean;
    }

    /**
     * 微信通知结果转换
     *
     * @param resMap    微信通知结果
     */
    public static PaymentNotifyBean wxnotifyConver(Map<String, String> resMap) {
        PaymentNotifyBean paymentNotifyBean = new PaymentNotifyBean();
        paymentNotifyBean.setAttach(resMap.get("attach"));
        paymentNotifyBean.setResultCode(resMap.get("result_code"));
        paymentNotifyBean.setBillCode(resMap.get("out_trade_no"));
        paymentNotifyBean.setInterfaceOrder(resMap.get("transaction_id"));
        paymentNotifyBean.setAmount(resMap.get("total_fee"));
        return paymentNotifyBean;
    }




}
